package Agents;

import java.awt.Color;

import Helpers.Common;
import Model.SimModel;
import Param.Constants;
import sim.engine.SimState;
import sim.engine.Steppable;
import sim.engine.Stoppable;
import sim.portrayal.simple.OvalPortrayal2D;
import sim.portrayal.simple.RectanglePortrayal2D;
import sim.util.Int2D;

@SuppressWarnings("serial")
public class Corpse extends OvalPortrayal2D implements Steppable
{
	protected SimModel model;
	private Stoppable stoppable;
	private Int2D position;
	private Virus virus;
	
	/**
	 * Carré sous-jacent pour "dinner"
	 */
	protected RectanglePortrayal2D rectDinner = new RectanglePortrayal2D(new Color(0, 205, 0, 255));
	
	public Corpse(SimModel model, Int2D p, Virus v){
		this.model = model;
		this.position = p;
		this.virus = v;
		v.setHost(this);
		
		// Initialisation de la couleur de l'agent
		this.paint = Color.black;
	}
	
	public Int2D getPos(){
		return position;
	}
	
	public int beEaten() 
	{
		return Constants.EAT_HEALING_POWER;
	}

	public void turnIntoZombie(){
		int x = this.getPos().x;
		int y = this.getPos().y;
		
		model.addZombie(position);
		model.deleteCorpse();
		model.yard.remove(this);
		Common.removeRectangles(this.model.yard, x, y);
		stoppable.stop();
		//System.out.println("Corps -> Zombie");
	}
	
	protected void displayRectDinner()
	{
		rectDinner.filled = false;
		this.model.yard.setObjectLocation(rectDinner, this.getPos());
	}
	
	/**
	 * Algorithme principal du cadavre
	 */
	@Override
	public void step(SimState state) 
	{
		int x = this.getPos().x;
		int y = this.getPos().y;
		
		virus.step();
		Common.removeRectangles(this.model.yard, x, y);
	}
	
	public void setStoppable(Stoppable stoppable) {
		this.stoppable = stoppable;
	}
}
